<?php

//编辑器字段
function editor($field, $value, $fieldinfo) {
    $setting = unserialize($fieldinfo['setting']);
    extract($setting);
    extract($fieldinfo);

    $disabled_page = isset($disabled_page) ? $disabled_page : 0;
    //编辑器高度
    if (!$height)
        $height = 300;
    //是否允许上传
    $allowupload = defined('IN_ADMIN') ? 1 : $grouplist['allowattachment'] ? 1 : 0;
    //内容
    if (!$value)
        $value = $defaultvalue;
    if ($minlength || $pattern)
        $allow_empty = '';

    $form = form::editor($field, $toolbar, 'content', $this->catid, '', $allowupload, 1, '', $height, $disabled_page);
    //在formValidator里面加入 实例化编辑的JS代码 editor_config_content
    $this->formValidator .= "
            //编辑器
            editor$field = new baidu.editor.ui.Editor(editor_config_$field);
            editor$field.render( '$field' );
    ";
    //设置JS提示。
    if ($minlength) {
        $this->formValidator .= '
            $("#' . $field . '").formValidator({' . $allow_empty . 'onshow:"",onfocus:"' . $errortips . '"}).functionValidator({
	    fun:function(val,elem){
	        var data = editor' . $field . '.hasContents();
	        if($(\'#islink\').is(\':checked\')){
                                    return true;
	        } else if(($(\'#islink\').is(\':checked\')==false) && data==false){
                                    editor' . $field . '.focus();
                                    return "' . $errortips . '";
	        } else if (data==false) {
                                    editor' . $field . '.focus();
                                    return "' . $errortips . '";
	        }
                            return true;
	   }
            });';
    }
    return "<div id='{$field}_tip'></div>" . '<script type="text/plain" id="' . $field . '" boxid="' . $field . '">' . $value . '</script>' . $form;
}

?>